'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/user/pub/is_show 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			out_trade_no, //充值订单号
			tv_id,
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		let copyright_show = 99999
		let copyright_noshow = 0
		let get_tv = await db.collection('a_tv').where({
			_id: tv_id
		}).get()
		try {
			copyright_show = get_tv.data[0].copyright_show || 99999
			copyright_noshow = get_tv.data[0].copyright_noshow || 0
		} catch (err) {
			return res
		}

		let OrderNum = await vk.baseDao.count({
			dbName: "a_recharge", // 表名
			whereJson: { // 条件
				pay_status: 1,
				tv_id: tv_id,
			}
		});

		let is_updata = OrderNum % Number(copyright_show + copyright_noshow)

		// let xxx = await vk.baseDao.add({
		// 	dbName: "vk-test", // 表名
		// 	dataJson: {
		// 		is_updata: is_updata,
		// 		OrderNum: OrderNum,
		// 		copyright_show: copyright_show,
		// 		copyright_noshow: copyright_noshow
		// 	}
		// });


		if (is_updata > copyright_show || is_updata == 0) {
			let updata_isshow = await vk.baseDao.update({
				dbName: "a_recharge", // 表名
				whereJson: { // 条件
					out_trade_no: out_trade_no
				},
				dataJson: { // 需要修改的数据
					isshow: false,
				}
			});
		}


		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}